<template>
	<view id="publicity">
		<view class="vote-cont" v-for="(item,index) in publicityList" :key="item.id" style="padding: 10px 20px;">
			<view style="padding: 10px 20px;background: #fff;" @click="voteDetail(item)">
				<view class="title">
					{{ item.vote_name }}
					<text v-if="item.vote_state==0 && item.redDotsSelectTotal == 0" class="redDotsStyle"></text>
				</view>
				<view style="margin-top: 10px;">发布时间：{{item.begin_time}}</view>
			</view>
		</view>
		<view v-if="publicityList.length == 0">
			<view style="width: 232px;height: 242px;margin: 110px auto;">
			  <image style="width: 100%;height: 100%;" src="../../../static/image/9015d0e9f45344c4007d408cd271f6a.png" mode=""></image>
			</view>
			<view style="width: 62%;margin: -66px auto;text-align: center;color: #999;">暂无数据</view>
		</view>
		<u-toast ref="uToast" />

		<view style="position: relative;">
			<view class="meeting-dialog">
				<u-popup v-model="isSencond" mode="center" border-radius="14">
					<view class="meeting-wrap">
						<view class="meeting-title">
							未提交认证
						</view>
						<view class="meeting-start">
							<image class="img" src="../../../static/vote/seconded.png"></image>
						</view>
						<view class="meeting-cont">
							请先进行实名认证后进行附议
						</view>
						<view class="meeting-btn" @click="submit()">
							提交认证
						</view>
					</view>
				</u-popup>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		props: ['voteId', 'communityName'],

		data() {
			return {
				isSencond: false,
				userId: uni.getStorageSync('rawData').userId,
				voteUserInfo: {}, //投票用户信息
				publicityList : [],
			}
		},
		mounted() {
			this.getVoteUserInfo();
			this.getPublicityList();
		},
		
		methods: {
			getPublicityList() {
				console.log("查黑车")
				this.$requestYz.api.getPublicityListById({
					id: this.voteId,
					user_id : this.userId
				}).then(res => {
					this.publicityList = res.data.data.datalist
				})
			},
			//投票用户信息，无数据需认证
			getVoteUserInfo() {
				this.$requestYz.api.getVoteUserInfo({
					vote_id: this.voteId,
					user_id: this.userId
				}).then(res => {
					this.voteUserInfo = res.data.data
				})
			},
			//提交认证
			submit() {
				this.isSencond = false;
				console.log(this.voteId)
				console.log(this.communityName)
				uni.navigateTo({
					url: './submitAuth?vote_id=' + this.voteId + "&proName=" + this.communityName
				})
			},
			voteDetail(item) {
				if (!this.voteUserInfo.id || !this.voteUserInfo.building_number) {
					this.isSencond = true;
					return;
				}
				var recordType = item.vote_type;
				if(recordType == 0 || recordType == 1 
				||recordType == 2 ||recordType == 5 
				||recordType == 6  ||recordType == 8
				||recordType == 10 ||recordType == 11
				||recordType == 20 || recordType == 13
				 ){
					if (item.vote_state == 1) {
						this.$refs.uToast.show({
							title: item.vote_name + '已结束',
							type: 'warning',
							icon: false
						})
						return;
					}
				}
				
				//添加查看记录
				this.$requestYz.api.addRedDotsSelectInfo({
					p_id: item.id,
					user_id: this.userId
				}).then(res => {
					if(res.data.data.data == 1){
						item.redDotsSelectTotal = 1
						//调用父级页面方法，更新顶部导航红点
						this.$emit("ToChangeRedDots");
					}
					
				})
				//成立业委会附议
				if (item.vote_type == 0) {
					this.$emit('changeIndex', 0);
					return
				}
				//招募筹备组公示
				if (item.vote_type == 1) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/publicityDetail?id=${item.id}`
					})
					return
				}
				//筹备组投票
				if (item.vote_type == 2) {
					this.$emit('changeIndex', 0);
					return
				}
				//筹备组成员公示
				if (item.vote_type == 3) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/nameList?id=${item.essential_information_id}&typeName=1`
					})
					return
				}
				//业主规约公示
				if (item.vote_type == 4) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/ownerRule?id=${item.essential_information_id}`
					})
					return;
				}
				//招募委员公示
				if (item.vote_type == 5) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/publicityDetail?id=${item.id}`
					})
					return;
				}
				//委员报名人公示
				if (item.vote_type == 6) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/nameList?id=${item.essential_information_id}&typeName=2`
					})
					return;
				}
				
				//首次业主大会通知
				if (item.vote_type == 7) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/ownerNotice?id=${item.essential_information_id}`
					})
					return;
				}

				//委员投票
				if (item.vote_type == 8) {
					this.$emit('changeIndex', 0);
					return;
				}

				//委员信息公示
				if (item.vote_type == 9) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/nameList?id=${item.essential_information_id}&typeName=3`
					})
					return;
				}
				//主任投票 副主任投票
				if (item.vote_type == 10 || item.vote_type == 11) {
					this.$emit('changeIndex', 0);
					return;
				}
				//业委会职位结果公示
				if (item.vote_type == 12) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/nameList?id=${item.essential_information_id}&typeName=4`
					})
					return;
				}
				
				//工作组组长投票
				if (item.vote_type == 13) {
					this.$emit('changeIndex', 0);
					return;
				}
				//委托人招募
				if (item.vote_type == 14) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/publicityDetail?id=${item.id}`
					})
					return
				}
				//委托人投票
				if (item.vote_type == 15) {
					this.$emit('changeIndex', 0);
					return;
				}
				//委托人公示
				if (item.vote_type == 16) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/nameList?id=${item.essential_information_id}&typeName=5`
					})
					return;
				}
				//解聘物业业主大会投票
				if (item.vote_type == 17) {
					this.$emit('changeIndex', 0);
					return
				}
				//解聘物业业主大会公示
				if (item.vote_type == 18) {
					
					return
				}
				//竞争性谈判小组业主报名
				if (item.vote_type == 19) {
					uni.navigateTo({
						url: `/pages/vote/components/publicity/publicityDetail?id=${item.id}`
					})
					return
				}
				//竞争性小组业主投票
				if (item.vote_type == 20) {
					this.$emit('changeIndex', 0);
					return;
				}
				//选聘物业决议公示
				if (item.vote_type == 21) {
					this.$emit('changeIndex', 0);
					return;
				}
				return;
			},

		}
	}
</script>

<style lang="scss">
	.redDotsStyle {
		width: 20rpx;
		height: 20rpx;
		line-height: 30rpx;
		background: red;
		border-radius: 50%;
		font-size: 24rpx;
		color: #fff;
		margin-left: 10px;
		position: absolute;
	}
	#publicity {

		.meeting-dialog {
			position: relative;

			::v-deep .u-mode-center-box {
				width: 670rpx !important;
				height: 800rpx;
				background: #FFFFFF !important;
				border-radius: 12rpx !important;
			}

			.meeting-wrap {
				padding: 40rpx;
			}

			.meeting-title {
				font-size: 18px;
				font-weight: bold;
				padding-bottom: 20px;
				border-bottom: 1px solid #E7ECE1;
			}

			.meeting-start {
				margin: 40rpx 0 24rpx;
				font-size: 16px;
				font-weight: bold;

				.img {
					width: 160px;
					height: 114px;
					margin: 0 auto;
					transform: translate(74px, 8px);
				}
			}

			.meeting-cont {
				color: red;
				font-size: 32rpx;
				border-bottom: 60rpx;
				margin-top: 50rpx;
				margin-bottom: 120rpx;
				text-align: center;
			}

			.succ {
				color: #333300;
				font-weight: bold;
			}

			.meeting-btn {
				width: 350rpx;
				height: 88rpx;
				line-height: 88rpx;
				background: #FFFFFF;
				border-radius: 22px;
				border: 1px solid #427705;
				text-align: center;
				color: #427705;
				margin: 40px auto;
				font-weight: bold;
			}
		}

		.vote-wrap {
			width: 100%;
			height: 204rpx;
			background: #FFFFFF;
			margin-top: 20rpx;
		}

		.vote-item {
			padding: 40rpx 30rpx;
		}

		.title {
			font-weight: bold;
			font-size: 32rpx;
		}

		.date {
			margin-top: 40rpx;
			font-size: 28rpx;
		}

	}
</style>
